﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace TuongLai_Schools
{
    public class DbConnection
    {
        private static SqlConnection _cnn = new SqlConnection(clsCommon.sConnectionString);
        public static SqlConnection SqlConnection
        {
            get { return _cnn; }
            set { _cnn = value; }
        }

        public static void Open()
        {
            _cnn.Open();
        }

        public static void Close()
        {
            _cnn.Close();
        }
    }

   public class DbAccess
    {
       SqlCommand cmd;
       #region Open and Close Connection
   
       private void Open()
       {
           DbConnection.Open();
       }
   
       private void Close()
       {
           DbConnection.Close();
       }
       #endregion

       public void CreateNewSqlCommand_Proc()
       {
           cmd = new SqlCommand();
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Connection = DbConnection.SqlConnection;
       }
       public void CreateNewSqlCommand_Text()
       {
           cmd = new SqlCommand();
           cmd.CommandType = CommandType.Text;
           cmd.Connection = DbConnection.SqlConnection;
       }
        #region Execute sqlComman
       public SqlDataReader ExecuteReader(string sProcName)
       {
           try
           {
               cmd.CommandText = sProcName;
               this.Open();
               return cmd.ExecuteReader(CommandBehavior.CloseConnection);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }
        #endregion

    }
}
